<#--
附件控件
attachmentName：附件名的控件名称
id：附件ID的控件名称
value：附件ID列表（用逗号间隔，如：1,2,3）
showType：控件显示类型：上传upload/下载download/全部all
<@attachmentFix attachmentName="${control.name}" id="${control.name}" value="${control.value?if_exists}" showType="all" />
-->
<#macro attachment id="" name="" value=""    namePrefix="" showType="all" required="false" extra...>
	
	<#local value = value?replace(" ","")>
	<script>
		var fileids = "";
		var fileNames = "";
		var fileLinks = "";
		<#if value != "">
			var url = "<@context/>common/download/getFileNamesByIds.do";
			$.ajax({url: url,
				type: 'GET',
				async: false,
				cache: false,
				<#--
				dataType: 'html',
				-->
				data: ({fileToDownload: "${value?if_exists}"}),
				timeout: 20000,
				error: function(){
					alert('更新附件名称出错！');
					return false;
				},
				success: function(data){
				    fileids = $(data)[0].value;
					fileNames = $(data)[2].value;
					fileLinks = data;
					 <#--
					alert("fileids=" + fileids + "  fileNames=" + fileNames + "  fileLinks=" + fileLinks)
					 -->
				}
			});
		</#if>
		
		/**
		 * 附件控件事件
		 */
		function attachWindow2(objId, objName) {
				var fvalue = objId + "," + objName;
				art.dialog.open(ctx + "common/upload/upload.do?fname=" + fvalue,{id:"attachementDialog",title:"上传附件",width:"600px",height:"400px"});
				art.dialog.data('parentWindow',window)
		}
	</script>
	<#--查看/下载-->
	<#if showType="upload">
		<span id="${id}_span" class="input-append">
		<input type="text" id="filename${id}" name="filename${id}" value="" readonly="true" class="input-medium" data-type="attachment"/>
	    <input type="hidden" id="fileid${id}" name="${namePrefix}${name}" value="">
		<input name="btnSelect" type="button" class="btn" value="选 择" onclick="attachWindow2('fileid${id}','filename${id}')">
		<script>
			$("input[id='filename${id}']").val(fileNames);
			$("input[id='fileid${id}']").val(fileids);
		</span>
		<#if required?default("false") == "true">
			<span style="color:red;">*</span>
		</#if>
		</script>
	<#elseif showType="download">
		<span id="filedownload${id}" name="filedownload${id}"></span>
		<script>
			$("span[id='filedownload${id}']").html(fileLinks);
		</script>
	<#elseif showType="all">
		<span id="${id}_span" class="input-append">
 
			<div class="input-group">
				  <input type="text" id="filename${id}" name="filename${id}" value="" readonly="true" class="form-control" data-type="attachment"/>
			      <input type="hidden" id="fileid${id}" name="${namePrefix}${name}" value="">
			      <span class="input-group-btn">
			        <button class="btn btn-secondary  btn-default" type="button"  onclick="attachWindow2('fileid${id}','filename${id}')">选 择</button>
			      </span>
			</div>
			<script>
				$("input[id='filename${id}']").val(fileNames);
				$("input[id='fileid${id}']").val(fileids);
				$("div[id='filedownload${id}']").html(fileLinks);
			</script>
		</span>
		<#if required?default("false") == "true">
			<span style="color:red;">*</span>
		</#if>
		<div id="filedownload${id}" name="filedownload${id}"></div>
	</#if>
</#macro>